function UserUsAssTempHp(){
	this.form=this.InitForm();
	this.tab=this.InitEleUI();
	//this.InItPage();
	this.table=this.InitTable();
	
	this.currenttabindex=0;
	
	$("#year").val($("#hidyear").val());
	this.form.render('select');
	this.InitGrid();
}


UserUsAssTempHp.prototype.InitGrid=function (){
	var year=$("#year").val();
	var quarter=$('input[name="quarter"]:checked ').val();
	
	var _this = this;
    window.liger.remove("listorg");
    if (_this.grid == null) {
        _this.grid = $("#listorg").ligerGrid({
            columns: [{ display: '序号', width: 80, name: 'rowNum' },
                     { display: '机构名称', width:250, align:'left',name: 'orgname',id:"orgname"},
                     { display: '年份', width: 80, name: 'year' },
                     { display: '季度', width: 80, name: 'quarter' },
                     { display: '人数', width: 80, name: 'usercount',
                         render:function(rowData){
                             if(rowData.realcount ==undefined ||rowData.realcount ==null||rowData.realcount ==''){
                             	 console.log("1:"+rowData.usercount);
                                 return rowData.usercount;
                             }else{
                                 console.log("2:"+rowData.realcount);
                                 return rowData.realcount;
                             }
                         }
					 },
                     { display: '自评', columns:
                         [
                          { display: '总计', name: 'zpcount', align: 'center', width: 60 },
                          { display: '填写', name: 'zptxcount', width: 60, align: 'center' },
                          { display: '提交', name: 'zptjcount', width: 60, align: 'center' },
//                          { display: '审核', name: 'zpshcount', width: 60, align: 'center' },
//                          { display: '归档', name: 'zpgdcount', width: 60, align: 'center' },
//                          { display: '驳回', name: 'zpbhcount', width: 60, align: 'center' }
                      ] },
                      { display: '互评', columns:
                          [
                           { display: '总计', name: 'hpcount', align: 'center', width: 60 }, 
                           { display: '填写', name: 'hptxcount', width: 60, align: 'center' },
                           { display: '提交', name: 'hptjcount', width: 60, align: 'center' },
//                           { display: '审核', name: 'hpshcount', width: 60, align: 'center' },
//                           { display: '归档', name: 'hpgdcount', width: 60, align: 'center' },
//                           { display: '驳回', name: 'hpbhcount', width: 60, align: 'center' }
                       ] },
                     {display: '操作', width: 80, name: 'userid', render: function (rowdata, rowindex, value) {
                    		var html='';
                        	if(rowdata.usercount>0){
                        		if(rowdata.hptxcount>0)
                        			{
                        			html+=' <img class="btn-img" src="'+ctxStatic+'/images/button/tijiao.png" onclick="vUserUsAssTempHp.BmTiJiao('+rowdata.orgid+','+rowdata.year+','+rowdata.quarter+',1,'+rowdata.orgstatustjid+')"  alt="提交" title="提交">';
                        			}
                        		//html+=' <img class="btn-img" src="'+ctxStatic+'/images/button/tijiao.png" onclick="vUserUsAssTempHp.BmTiJiao('+rowdata.orgid+','+rowdata.year+','+rowdata.quarter+',1,'+rowdata.orgstatustjid+')"  alt="提交" title="提交">';
                        	}
                        	return html;
                     }}
            ],
            pageSize: 30,
            url: "get_list_org_hp" + '?time=' + new Date().getTime(),
            delayLoad: false,            //初始化时是否加载,为true时,不加载,为false时,则加载
            sortName: null,
            dataAction: 'server',
            parms: {
                Method: "",
                year: year,quarter:quarter
            },
            sortOrder: null,
            sourceObj: _this.grid,
            root: 'items',                       //数据源字段名
            record: 'countRecord',                    //数据源记录数字段名
            pageParmName: 'CurrentPage',               //页索引参数名，(提交给服务器)
            pagesizeParmName: 'PageSize',        //页记录数参数名，(提交给服务器)
            data: {},
            width: "100%",
            height: '100%',
            heightDiff: 0,
            rowHeight:28,
            onSuccess: function (rowdata, rowindex) { if (rowdata.status > 0) { alert(rowdata.msg) } },
            alternatingRow: true,
            border: 0,
            usePager:false,
            tree:{
            	columnId:"orgname",
            	idField:"orgid",
            	parentIDField:"orgparentid"
            	
            }
        })
    }
}

UserUsAssTempHp.prototype.InitTable = function() {
	var year=$("#year").val();
	var quarter=$('input[name="quarter"]:checked ').val();
	var table;
	var _this=this;
	layui.use('table', function() {
	    table = layui.table;
		table.render({
			elem : '#list'
			,height : $(window).height() - 150
			,url : 'get_pjlist' // 数据接口
			,page : true // 开启分页
			,limit : 40
			,id: 'hplist'
			,method:"post"
			,limits:[20,40,80,100]
			,cols : [ [ // 表头
			           //{type:'numbers'}
			           //,{field : 'rowNum',title : '序号',width : 60,align : 'center'}
			           {field : 'realname',title : '姓名',width : "7%",align : 'center',fixed: 'left',templet: '#realnameTpl'}
			           , {field : 'cardno',title : '身份证号',width : "15%",align : 'center'}
			           , {field : 'realorgname',title : '实际工作单位',width : "18%",align : 'center'}
			           //, {field : 'templatename',title : '模板',width : 150,align : 'center'}
			           , {field : 'year',title : '年份',width : "6%",align : 'center'}
			           , {field : 'quarter',title : '季度',width : "7%",align : 'center'}
			           , {field : 'totalscore',title : '得分 ',width : "5%",align : 'center'}
			          // , {field : 'pjjg',title : '结果',width : "6%",align : 'center'}
			           , {field : 'status',title : '状态',width : "7%",align : 'center'}
			           //, {field : 'zpstatus',title : '进度',width : 100,align : 'center'}
			           , {title : '进度',width : "12%",align : 'center',toolbar : '#process'}
			           , {title : '特殊事项说明',width : "9%",align : 'center',toolbar : '#operate1'}
			           //, {field : 'createtime',title : '时间',width : 170,align : 'center'}
			           , {title : '操作',width : "12%",align : 'center',toolbar : '#operate'}
		            ] ]
		    ,request:{
				type:'post'
			}
			,where:{year: year,quarter:quarter,pjtype:0,realname:$("#realname").val()}
		    ,done: function(res, page, count){
		    	var dataarr=res.data;
		    	$("[data-field='quarter']").children().each(function(index){ 
		    		var text=$(this).text();
		    		switch(text){
		    		case "1":
		    			$(this).text('第一季度');
		    			break;
		    		case "2":
		    			$(this).text('第二季度');
		    			break;
		    		case "3":
		    			$(this).text('第三季度');
		    			break;
		    		case "4":
		    			$(this).text('第四季度');
		    			break;
		    		}
               })  
                $("[data-field='status']").children().each(function(index){
		    		var text=$(this).text();
		    		
		    		switch(text){
		    		case "-1":
		    			$(this).text('未填写');
		    			break;
		    		case "0":
		    			$(this).text('已填写');
		    			break;
		    		case "1":
		    			$(this).text('提交');
		    			break;
		    		case "2":
		    			$(this).text('审核');
		    			break;
		    		case "3":
		    			$(this).text('归档');
		    			break;
		    		case "4":
		    			$(this).text('驳回');
		    			break;
		    		}
             })
                $("[data-field='realorgname']").children().each(function(index){
                    if (index > 0) {
                        var thisdata = dataarr[index - 1];
                        var text = $(this).text();
                        if (text == null || text == ''){
                            var orgname = thisdata.orgname;
                            console.log(1);
                            $(this).text(orgname);
                        }
                    }
                })
               
		    }
		    
		});

		
		 //监听工具条
	    table.on('tool(list)', function(obj){
	      var data = obj.data;
	      if(obj.event === 'detail'){
	    	  vUserUsAssTempHp.ChangeTab(2,data.year,data.quarter,data.userid);
	    	  
	      } else if(obj.event === 'del'){
	        top.mylayui.confirm('确定要删除吗？',{icon: 0}, function(index){
	        	 top.mylayui.close(index);
	        	 vUserUsAssTempHp.deleteentity(data.usasspjid,data.userid);
	        });
	      } else if(obj.event === 'edit'){
	    	  vUserUsAssTempHp.openadd(data.userid,data.year,data.quarter,data.usasspjid);
	      }
	      else if(obj.event === 'add'){
	    	  vUserUsAssTempHp.openadd(data.userid,data.year,data.quarter,0);
		  }
	      else if(obj.event === 'tijiao'){
	    	  top.mylayui.confirm('提交后不允许修改，确定要提交吗？',{icon: 0}, function(index){
		        	 top.mylayui.close(index);
		        	 vUserUsAssTempHp.updatestatus(data.usasspjid,1,data.year,data.quarter,data.userid);
		        });
		  }
	      else if(obj.event==='wjsm'){
	    	  vUserUsAssTempHp.openwjsm(obj.data.userid,data.year,data.quarter);
	      }
	    });

	    
	});
	
	return table;
}

UserUsAssTempHp.prototype.ChangeTab=function(index,year,quarter,userid){
	this.tab.tabChange('tabcontent', index);
	vUserUsAssTempHp.InitIfream(year,quarter,userid)
}

UserUsAssTempHp.prototype.InitForm=function(){
	var form;
	layui.use('form', function(){
       form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
       form.on('select(year)', function (data) { 
    	   vUserUsAssTempHp.InItPage();
       });
       form.on('radio(quarter)', function(data){
    	   vUserUsAssTempHp.InItPage();
       })
       
	   form.render();
	});  
	return form;
}
UserUsAssTempHp.prototype.InitEleUI=function(){
	var element;
	var _this=this;
    $("#year").val($("#hidyear").val());
	layui.use('element', function(){
       element=layui.element;
       
       element.on('tab(tabcontent)', function(data){
    	  vUserUsAssTempHp.currenttabindex=data.index;
    	  if(data.index==1){
    		  _this.searchtable();
    	  }
	}); 
	})
	return element;
}


UserUsAssTempHp.prototype.InItPage=function(){
	if(vUserUsAssTempHp.currenttabindex==0){
		vUserUsAssTempHp.searchlist();
	}else if(vUserUsAssTempHp.currenttabindex==1){
		vUserUsAssTempHp.searchtable();
	}
	else{
		 //vUserUsAssTempHp.InitIfream();
	}
}

UserUsAssTempHp.prototype.InitIfream=function(vyear,vquarter,userid){
	var year="";
	if(vyear){
		year=vyear;
	}
	else{
		year=$("#year").val();
	}
	var quarter="";
	if(vquarter){
		quarter=vquarter;
	}
	else{
		quarter=$('input[name="quarter"]:checked ').val();
	}
	if(year==""||quarter==""){
		top.mylayui.msg('参数有误', {icon: 0});
		return;
	}
	$("#getdata").attr("src","user_usasstemp_hp_show?year="+year+"&quarter="+quarter+"&userid="+userid);
}


UserUsAssTempHp.prototype.openadd=function(userid,year,quarter,usasspjid){
//	top.mylayui.open({
//        type: 2,
//        title: '填写评价',
//        shadeClose: true,
//        shade: 0.5,
//        area: ['1000px', '600px'],
//        content: 'userusasstemppj/user_usasstemp_hp_edit'
//      }); 
	top.mylayui.open({
        type: 2,
        title: '填写评价',
        shadeClose: true,
        shade: 0.5,
        area: ['1000px', '600px'],
        content: 'userusasstemppj/user_usasstemp_hp_edit_new?userid='+userid+"&nf="+year+"&quarter="+quarter+"&usasspjid="+usasspjid
      }); 
	
	
}

UserUsAssTempHp.prototype.addresult=function(result,msg){
	if(result>0){
		top.mylayui.msg('操作成功', {icon: 1});
		top.mylayui.closeAll('iframe');
		vUserUsAssTempHp.searchtable();
	}
	else{
		if(msg){
			top.mylayui.msg(msg, {icon: 0});
		}else{
			top.mylayui.msg('操作失败', {icon: 0});
		}
	}
}

UserUsAssTempHp.prototype.searchtable=function(){
	var year=$("#year").val();
	var quarter=$('input[name="quarter"]:checked ').val();
	this.table.reload('hplist', { 
		  page: {
	        curr: 1 //重新从第 1 页开始
	      }
	    ,where: {  
	    	year:year,
	    	quarter:quarter,
	    	pjtype:0
	    	,realname:$("#realname").val()
	    }  
	}); 
}

UserUsAssTempHp.prototype.deleteentity=function(usasspjid,userid){
	$.ajax({
		type:"POST",
		url:"delete_useruathp",
		data:{usasspjid:usasspjid,userid:userid},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
				top.mylayui.msg(data.msg, {icon: 1});
				//vOrg.searchtable();
				document.location.reload();
			}
			else{
				top.mylayui.msg(data.msg, {icon: 0});
			}
		},
		complete:function(XHR){
			
		},
		error:function(){
			
		}
	});
}

UserUsAssTempHp.prototype.searchlist = function () {
	var year=$("#year").val();
	var quarter=$('input[name="quarter"]:checked ').val();
    this.grid.setOptions({
        newPage: 1, parms: {
            Method: "",
            year: year,quarter:quarter
        }
    });
    this.grid.loadData();
}


UserUsAssTempHp.prototype.updatestatus=function(usasspjid,status,year,quarter,userid){
	$.ajax({
		type:"POST",
		url:"update_hp_status",
		data:{usasspjid:usasspjid,status:status,year:year,quarter:quarter,userid:userid},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
				top.mylayui.msg(data.msg, {icon: 1});
				//vOrg.searchtable();
				document.location.reload();
			}
			else{
				top.mylayui.msg(data.msg, {icon: 0});
			}
		},
		complete:function(XHR){
			
		},
		error:function(){
			
		}
	});
}

UserUsAssTempHp.prototype.openwjsm=function(userid,year,quarter){

	top.mylayui.open({
        type: 2,
        title: false,
        shadeClose: true,
        shade: 0.5,
        area: ['700px', '250px'],
        content: 'common/user_vtdp?userid='+userid+"&year="+year+"&quarter="+quarter
      });

}


UserUsAssTempHp.prototype.BmTiJiao=function(orgid,year,quarter,status,orgstatustjid){
	top.mylayui.confirm('提交后不允许修改，确定要提交吗？',{icon: 0}, function(index){
   	 top.mylayui.close(index);
   	$.ajax({
		type:"POST",
		url:"update_hp_status_bm",
		data:{orgid:orgid,year:year,quarter:quarter,status:status,orgstatustjid:orgstatustjid},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
				top.mylayui.msg(data.msg, {icon: 1});
				//vOrg.searchtable();
				vUserUsAssTempHp.InItPage();
			}
			else{
				top.mylayui.msg(data.msg, {icon: 0});
			}
		},
		complete:function(XHR){
			
		},
		error:function(){
			
		}
	});
	})
	
}

var vUserUsAssTempHp=null;
$(function(){
	vUserUsAssTempHp=new UserUsAssTempHp();
})